package com.itshizhan.demo01.interceptor;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Enumeration;

/**
 * @author itshizhan
 * @email 370424110@qq.com
 * @date 2021-08-05
 */
@Slf4j
public class JwtInterceptor implements HandlerInterceptor {
    /**
     * 请求执行前执行的, 默认返回true，继续执行
     * @param request
     * @param response
     * @param handler
     * @return
     * @throws Exception
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        log.info("LoginInterceptor 开始运行");
        String token = request.getHeader("token");
        if (!StringUtils.hasLength(token)){
           throw new RuntimeException("Token校验失败");
        }
        return true;
    }
}
